package com.example.model_service.controller;

import com.example.model_service.dto.QueryDTO;
import com.example.model_service.service.ObjInfoService;
import com.example.model_service.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.checkerframework.checker.units.qual.A;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import jakarta.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/model")
@CrossOrigin
@Api("模型管理功能")
public class ModelController {

    @Resource
    private ObjInfoService objInfoService;

    @ApiOperation("查询模型列表")
    @PostMapping("query")
    public Result query(@RequestBody QueryDTO queryDTO){
        return objInfoService.queryModels(queryDTO);
    }

    @ApiOperation("上传模型")
    @PostMapping("/upload")
    public Result upload(@RequestParam("file")MultipartFile file, @RequestParam("userId") Integer userId){
        return objInfoService.uploadModel(file, userId);
    }

    @ApiOperation("下载模型")
    @GetMapping("/download")
    public ResponseEntity<byte[]> download(@RequestParam("id") Integer id, HttpServletResponse response) {
        return objInfoService.downloadModel(id, response);
    }

    @ApiOperation("删除模型")
    @GetMapping("/remove")
    public Result remove(@RequestParam("id") Integer id){
        return objInfoService.removeModel(id);
    }

    @ApiOperation("获取所有的模型")
    @GetMapping("/queryAll")
    public Result queryAll(@RequestParam("userId")Integer userId){
        return objInfoService.queryAllModels(userId);
    }

}
